#!/usr/bin/env bash

# 修改项目app的路径
OBJDIR=/root/go-weixin-obj-new/src/go-weixin/app 

USERAPI=usercenter/api 
USERRPC=usercenter/rpc 
MUSICAPI=music/musicapi 
MUSICRPC=music/musicrpc 
DIARYRPC=diary/rpc 
DIARYAPI=diary/api 
GUITARRPC=guitar/rpc 
GUITARAPI=guitar/api 
MQTASK=mqueue/tasks
CGO_ENABLED=0

# 设置版本号
export GO_WEIXIN_VERSION=1
export CGO_ENABLED=0

echo "--Build with userapi--"
cd $OBJDIR/$USERAPI &&
    rm -f UserApiServer &&
    go build -o UserApiServer &&
    docker build -t go-user-api:v$GO_WEIXIN_VERSION .

echo "--Build with userrpc--"
cd $OBJDIR/$USERRPC &&
    rm -f UserRpcServer &&
    go build -o UserRpcServer &&
    docker build -t go-user-rpc:v$GO_WEIXIN_VERSION  .

echo "--Build with musicapi--"
cd $OBJDIR/$MUSICAPI &&
    rm -f MusicApiServer &&
    go build -o MusicApiServer && 
    docker build -t go-music-api:v$GO_WEIXIN_VERSION  .

echo "--Build with musicrpc--"
cd $OBJDIR/$MUSICRPC &&
    rm -f MusicRpcServer &&
    go build -o MusicRpcServer && 
    docker build -t go-music-rpc:v$GO_WEIXIN_VERSION  .

echo "--Build with diaryapi--"
cd $OBJDIR/$DIARYAPI &&
    rm -f DiaryApiServer &&
    go build -o DiaryApiServer && 
    docker build -t go-diary-api:v$GO_WEIXIN_VERSION  .

echo "--Build with diaryrpc--"
cd $OBJDIR/$DIARYRPC &&
    rm -f DiaryRpcServer &&
    go build -o DiaryRpcServer &&
    docker build -t go-diary-rpc:v$GO_WEIXIN_VERSION  .


echo "--Build with guitarrpc--"
cd $OBJDIR/$GUITARRPC &&
    rm -f GuitarRpcServer &&
    go build -o GuitarRpcServer &&
    docker build -t go-guitar-rpc:v$GO_WEIXIN_VERSION  .

echo "--Build with guitarapi--"
cd $OBJDIR/$GUITARAPI &&
    rm -f GuitarApiServer &&
    go build -o GuitarApiServer &&
    docker build -t go-guitar-api:v$GO_WEIXIN_VERSION  .


echo "--Build with mq-task--"
cd $OBJDIR/$MQTASK &&
    rm -f MqTaskServer &&
    go build -o MqTaskServer &&
    docker build -t go-mq-task:v$GO_WEIXIN_VERSION  .
echo "----Build success----"

echo "----开始启动----"
docker compose -f docker-compose.yal up -d
echo "----部署成功----"
echo "----docker ps 查看容器启动情况----"
